$(function(){
	var idname=sessionStorage.getItem('perOrderId');
	$('.GreenHeader h1.mui-title').html(idname);
	var arr={
		hf_s_id:"WD11",
		hf_srv_id:"Pv_jpo_dtl_get",
		hs_action_id:"submit",
		hs_po_id:idname,
		hf_locale_id:"en"
	};
	getAjaxRequest(arr,function(result){
		if (result.bs_result == BS_RESULT.OK) {
			$('.preOrderBox').html('<img src="'+MPJ.apiBase+result.bs_p3_file_id+'" />'+
						'<div class="main">'+
						'<h4>'+result.bs_po_note+'</h4>'+
						'<div class="deadline">Order deadline: <strong>'+result.bs_po_end_dt+'</strong></div>'+
						'<a href="javascript:void(0)" class="terms">Terms & Conditions</a>'+
						'</div>');

			var str='';
			var bvc_pdt = result.bc_group_a_pdt.bvc_pdt;
			if(bvc_pdt.length != 0){
				for (var j = 0; j < bvc_pdt.length; j ++) {
					var product = bvc_pdt[j];
					var isOffer= product.bs_is_offer == "Y" ? '<span><em>offer</em></span>' : '';
					var bs_prom_text=product.bs_prom_text == "" ? "" : product.bs_prom_text;
					str+='<li data-id="'+product.bj_pdt_id+'" data-item-no="'+product.bs_item_no+'">'+
						'<div class="mainCon">'+
						'<div class="imgBox">'+
						'<img src="'+MPJ.apiBase+''+product.bs_simg_file+'" />'+isOffer+
						'</div>'+
						'<div class="txtBox">'+
						'<h4>'+product.bs_brand+'</h4>'+
						'<p>'+product.bs_desc+'</p>'+
						'<div class="red-font">'+bs_prom_text +'</div>'+
						'<div class="price orange-font">$<em>'+product.bj_rsp+'</em></div>'+
						'<div class="num">'+
						'<div class="mui-numbox" data-numbox-min="1" >'+
						'<button class="mui-btn mui-numbox-btn-minus" type="button">-</button>'+
						'<input class="mui-numbox-input" type="number" value="1" />'+
						' <button class="mui-btn mui-numbox-btn-plus" type="button">+</button>'+
						'</div>'+
						'<div class="addCar">'+
						'Add<img src="' + MPJ.base + '/resources/images/icon/main-shopcar.png" />'+
						'</div>'+
						'</div>'+
						'</div>'+
						'</div>'+
						'</li>';
				}
			}
			$('.preOrderList.vertical-list ul').html(str);
			sessionStorage.removeItem('perOrderId');
			//两列数据的列表点击
			$('.preOrderList.vertical-list li').each(function(){
				var $this=$(this);
				//$this.on('tap','.imgBox',function(){
				//	var pdt_id=$this.data('id');
				//	var item_no=$this.data('item-no');
				//	var product_info={};
				//	product_info.pdt_id=pdt_id;
				//	product_info.item_no=item_no;
				//	sessionStorage.setItem('product_info',JSON.stringify(product_info));
				//	location.href=MPJ.base+"/pages/product/product-detail.jsp";
				//})
				$this.on('tap','.addCar',function(){
					var pdt_id=$this.data('id');
					var item_no=$this.data('item-no');
					var arr={
						hf_s_id:"WD11",
						hf_srv_id:"Av_jcart",
						hs_action_id:"add_all_to_cart",
						hvs_add_pdt_id:pdt_id,
						hvs_add_qty:$this.find('.mui-numbox-input').val(),
					};
					getAjaxRequest(arr,function(result){
						if(result.bs_result==BS_RESULT.OK){
							dialog('Message', 'Add to Shopping Cart', 1);
							var $dialog = $('#dialog');
							$dialog.show();
							$dialog.find('.comfirmBtn').one('click', function() {
								$dialog.hide();
								$dialog.remove();
								getCartSumCount();
							})
						}
					});
				})
			})

		}
	});


})